package com.taikang.hmp.hbusiness.diabetes.measure.sport.action.view;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.taikang.hmp.frame.common.TKException;
import com.taikang.hmp.frame.common.datastructre.Dto;
import com.taikang.hmp.frame.common.datastructre.support.BaseDto;
import com.taikang.hmp.frame.common.datastructre.support.ResponseDto;
import com.taikang.hmp.frame.common.web.action.BaseAction;
import com.taikang.hmp.hbusiness.diabetes.measure.sport.bean.Sport;
import com.taikang.hmp.hbusiness.diabetes.measure.sport.service.ISportService;

/** 
 * 运动
 * author:wyf
 * time:2015年8月5日 上午11:02:42
 */
public class SportViewAction extends BaseAction{
	private static Logger logger = LoggerFactory.getLogger(SportViewAction.class);
	
	private ISportService sportService;
	

	public ISportService getSportService() {
		return sportService;
	}

	public void setSportService(ISportService sportService) {
		this.sportService = sportService;
	}
	
	public String executeAction()  {
		// 显示运动折线图
		if ("showSportChart".equals(requestDto.getMethod())) {
			return showSportChart();
			// 显示运动表
		}else if("showSportRecord".equals(requestDto.getMethod())){
			
			logger.info("-- 显示运动记录  showSportRecord method--");
			return showSportRecord();
		}else if("showSportTable".equals(requestDto.getMethod())){
			
			logger.info("-- 显示运动表 showSportTable method--");
			return showSportTable();
		}  else {
			throw new TKException("no support method:"+requestDto.getMethod());
		}
	}

	/**
	 * 显示运动折线图
	 * 
	 * @return
	 */
	public String showSportChart() {
		logger.info("进入showSportChart方法体:"+requestDto.toString());
		//通用校验
		ResponseDto responseDto = new ResponseDto();			
		//获取参数
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		
		//String height = weightService.getHeight(jsonObj);
		List<Sport> records = sportService.getSportChartList(paramDto);
		Dto dto = new BaseDto();
		dto.put("records", records);
		responseDto.pushResultDto(dto);
		super.setDataMap(responseDto);
		
		
		return SUCCESS;
	}	
	/**
	 * 显示运动记录
	 * 
	 * @return
	 */
	public String showSportRecord() {

		logger.info("getMealChart:"+requestDto.toString());
		//通用校验
		ResponseDto responseDto = new ResponseDto();			
		//获取参数
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		
		//String height = weightService.getHeight(jsonObj);
		List<Sport> records = sportService.getSportRecordList(paramDto);
		Dto dto = new BaseDto();
		dto.put("records", records);
		responseDto.pushResultDto(dto);
		super.setDataMap(responseDto);
		//dataMap.put("resultMsg", "success");
		return SUCCESS;
	}
	/**
	 * 显示运动表
	 * 
	 * @return
	 */
	public String showSportTable()  {
		
		ResponseDto responseDto = new ResponseDto();
		//获取参数
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		//
		List<Sport> records = sportService.getSportTableList(paramDto);		
		Dto dto = new BaseDto();
		dto.put("records", records);
		responseDto.pushResultDto(dto);
		super.setDataMap(responseDto);
		return SUCCESS;		
	}	
}
